#ifndef MODULEMANAGER_H
#define MODULEMANAGER_H

#include <QMutex>
#include "singleton.h"
#include "basemanager.h"
#include "basemodule.h"

class ModuleManager : public BaseManager
{
    Q_OBJECT
public:
    ModuleManager(QObject *parent = nullptr);
    virtual ~ModuleManager();

    bool attach(BaseModule *module);
    bool detach(BaseModule *module);

    BaseModule *find(const QString &name);
    BaseModule *find(ModuleID id);
    BaseModule *find(uint magic);

    void print();

public slots:
    void onStart();

protected:
    virtual void customEvent(QEvent *event) override;

    void initHplcPump();
    void initHplcDetector();
    void initHplcCollector();
    void initHplcAutoSampler();

    void initTimeProgram();

    void initFlowmeter();
    void initSimpleFocController();

    void initLiChenElectronicSacle();
    void initShimadzuElectronicSacle();

private:
    QMutex 						*m_mutex = nullptr;
    QMap<uint, BaseModule*> 	m_modules;

    SINGLETON_DECLARE(ModuleManager)
};

#define moduleManager ModuleManager::getInstance()

#endif // MODULEMANAGER_H
